class MySql:
    __instance = None   # instance 实例
    ip = '127.0.0.1'
    port = 8080

    def __init__(self, ip, port):
        self.ip = ip
        self.port = port

    @classmethod
    def singleton(cls):   # singleton 单例模式
        if not cls.__instance:
            cls.__instance = cls(cls.ip, cls.port)
        return cls.__instance

# obj1 = MySql('127.0.0.1', 8080)
# obj2 = MySql('127.0.0.1', 8080)
obj1 = MySql.singleton()
obj2 = MySql.singleton()
print(obj1 is obj2)  # False